﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;

using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BUS;
using LinQ_DTO;
using System.Collections.Generic;


namespace EFashion.Employee
{
    public partial class management : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // thay doi login o day
            //int iDangNhap = (Int32)Session["IsLogin"];
            int iDangNhap = 0;
            if (Session["IsLogin"] != null && ((int)Session["IsLogin"] == 1))
                iDangNhap = 1;
            if (iDangNhap == 0)
            {
                Response.Redirect("~/Login.aspx");
            }
        }

        public void manage_customer()
        {
            String page = "1";

            String strPage = '"' + page + '"';

            RoleBUS role_BUS = new RoleBUS();
            aspnet_Role role = role_BUS.LayRoleTheoLoweredRoleName("customer");
            UsersInRoleBUS uir_BUS = new UsersInRoleBUS();
            List<aspnet_UsersInRole> uir_list = uir_BUS.LayDanhSachTheoRoleID(role.RoleId);

            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            int totalrow = uir_list.Count();
            String strTotalrow = '"' + totalrow.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            String strContext = "";

            int iStart = (int.Parse(page) - 1) * iLimit;
            int iEnd = iLimit * int.Parse(page);
            if (iEnd > totalrow)
            {
                iEnd = totalrow;
            }

            Response.Write("<div id='content_management'>");
            Response.Write("<h1 id='management_title'>Quản lý khách hàng</h1>");
            Response.Write("<br/>");
            Response.Write("<table border='0'><tbody><tr><td>");
            Response.Write("<input type='text' id='key_search' size='50' maxlength='100'/></td><td>");
            Response.Write("<div class='art-button-wrapper' valign='bottom'>");
            Response.Write("<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_search_customer(\"default\",\"-1\",\"10\",\"-1\");return false;'><span>Tìm kiếm</span></a>");
            Response.Write("</div>");
            Response.Write("</td></tr></tbody></table>");/*end: table tim_kiem */
            Response.Write("<div id='management_list'>");

            Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
            Response.Write("<tbody>");
            Response.Write("<tr class='management_table_header' style='text-align: center;'>");
            Response.Write("<td width='30%'>Tài khoản</td>");
            Response.Write("<td width='20%'>Ngày tham gia</td>");
            Response.Write("<td width='20%'>Ngày đăng nhập gần nhất</td>");
            Response.Write("<td width='15%'></td>");
            //Response.Write("<td width='15%'></td>");
            Response.Write("</tr>");

            int j = 1;
            String strSearch = '"' + "false" + '"';
            UserBUS user_BUS = new UserBUS();
            MembershipBUS membership_BUS = new MembershipBUS();
            aspnet_User user = new aspnet_User();
            aspnet_Membership membership = new aspnet_Membership();

            for (int i = iStart; i < iEnd; i++)
            {
                user = user_BUS.LayUserTheoId(uir_list[i].UserId);
                membership = membership_BUS.LayTheoUserId(uir_list[i].UserId);
                String strID = '"' + uir_list[i].UserId.ToString() + '"';

                if (j == 1)
                {
                    Response.Write("<tr class='management_celllight1'>");
                    j = 0;
                }
                else
                {
                    Response.Write("<tr class='management_celllight0'>");
                    j = 1;
                }
                Response.Write("<td align='left' style='padding: 5px;'>" + user.UserName + "</td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", membership.CreateDate) + "</td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", membership.LastLoginDate) + "</td>");

                Response.Write("<td align='center' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_view_detail_customer(" + strID + ");return false;'><span>Chi tiết</span></a>"
                    + "</div>" + "</td>");
                //Response.Write("<td align='center' style='padding: 5px;'>" +
                //    "<div class='art-button-wrapper'>" +
                //    "<span class='l'> </span>" +
                //    "<span class='r'> </span>" +
                //    "<a  class='art-button' href='#' onclick=';return false;'><span>Nhận xét</span></a>"
                //    + "</div>" + "</td>");
                Response.Write("</tr>");
            }
            Response.Write("</tbody>");
            Response.Write("</table>");
            Response.Write("</div>"); /*end: div management_list */

            Response.Write("<div align='center'>");
            strContext = '"' + "previous" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Lùi</span></a>" +
                "</div>");
            float fLimit = 10;
            double totalPage = Math.Ceiling(totalrow / fLimit);
            Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
            strContext = '"' + "next" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                "</div>");
            Response.Write("</div>"); /*end: div pageIndex */
            Response.Write("<div><select id=''>");
            strContext = '"' + "jump" + '"';
            for (int i = 1; i <= totalPage; i++)
            {
                if (i == int.Parse(page))
                {
                    Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                }
                else
                {
                    strCount = '"' + i.ToString() + '"';
                    Response.Write("<option id='' value='" + i + "' onclick='ajax_manage_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                }
            }
            Response.Write("</select></div>");/*end: select */
            Response.Write("</div>"); /*end: div content_management */
        }

    }
}
